package com.yazi.mxz.common.db.dao.impl;



import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.PrizeWinDao;
import com.yazi.mxz.common.entity.beans.Member;
import com.yazi.mxz.common.entity.beans.PrizeWin;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("prizeWinDao")
public class PrizeWinDaoImpl extends BasicDao<PrizeWin> implements PrizeWinDao {

	
	public PrizeWinDaoImpl() {
		super(PrizeWin.class);
		
	}

	@Override
	public Criteria getExample(PrizeWin prizeWin, String searchWord) {
		Criteria c = super.getExample(prizeWin, searchWord);
		
		// 用户奖品关联对象条件
		if (null != prizeWin) {
			// 用户
			Member member = prizeWin.getMember();
			if (null != member) {
				// 用户ID
				if (null != member.getMemberId()) {
					c.add(Restrictions.eq("member.memberId", member.getMemberId()));
				} else {
					// ...用户其它条件
				}
			}
			// ...用户奖品其它关联对象条件
		}
		
		// 关键字条件
		if (null != searchWord && !searchWord.isEmpty()) {
			c.createAlias("member", "member");
			// 关键字可查奖品名、兑换码、用户名
			String likeWord = "%" + searchWord + "%";
			c.add(Restrictions.or(
					Restrictions.like("name", likeWord),
					Restrictions.or(Restrictions.like("convertCode", likeWord),
							Restrictions.like("member.name", likeWord))));
		}
		return c;
	}
	
}
